package com.zkingsoft.services.lin.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkingsoft.dao.lin.LinOrderLogDao;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.model.lin.LinOrderLog;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.lin.LinOrderLogService;
import com.zkingsoft.util.ModelUtils;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2017-05-08 15:14
 */
@Service("linOrderLogService")
public class LinOrderLogServiceImpl implements LinOrderLogService {

	@Autowired
	private LinOrderLogDao linOrderLogDao;

	@Override
	public int add(LinOrderLog linOrderLog) {

		return linOrderLogDao.insert(linOrderLog);

	}

	@Override
	public int batchAdd(List<LinOrderLog> linOrderLogList) {
		int num = 0;

		int c = 10000;
		int size = linOrderLogList.size() / c + 1;
		for (int i = 0; i < size; i++) {
			int begin = i * c;
			int end = (i + 1) * c;
			end = end >= linOrderLogList.size() ? linOrderLogList.size() : end;
			List<LinOrderLog> insertList = linOrderLogList.subList(begin, end);
			num += linOrderLogDao.batchInsert(insertList);
		}
		return num;

	}

	@Override
	public int modifyByMap(LinOrderLog oldLinOrderLog,
			LinOrderLog newLinOrderLog) {

		if (!ModelUtils.isModified(oldLinOrderLog, newLinOrderLog)) {
			return 1;
		}
		Map<String, Object> modifyMap = null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldLinOrderLog,
					newLinOrderLog);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("orderLogId", oldLinOrderLog.getOrderLogId());
			linOrderLogDao.updateByMap(modifyMap);
		}
		return 1;
	}

	@Override
	public int modifyByModel(LinOrderLog linOrderLog) {

		return linOrderLogDao.updateByModel(linOrderLog);

	}

	@Override
	public int remove(List<Long> list) {

		return linOrderLogDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long orderLogId) {

		return linOrderLogDao.deleteById(orderLogId);

	}

	@Override
	public int removeByModel(LinOrderLog linOrderLog) {

		return linOrderLogDao.deleteByModel(linOrderLog);

	}

	@Override
	public List<LinOrderLog> findInPage(LinOrderLog linOrderLog,
			PaginationVO pageVo) {

		return linOrderLogDao.selectInPage(linOrderLog, pageVo);

	}

	@Override
	public List<LinOrderLog> findByModel(LinOrderLog linOrderLog) {

		return linOrderLogDao.selectByModel(linOrderLog);

	}

	@Override
	public int findTotal(LinOrderLog linOrderLog) {

		return linOrderLogDao.selectTotalRecord(linOrderLog);

	}

	@Override
	public LinOrderLog findById(Long orderLogId) {

		return linOrderLogDao.selectById(orderLogId);

	}

}